/*    */ package site;
/*    */ 
/*    */ import database.ConnectionDB;
/*    */ import database.DatabaseMysql;
/*    */ import java.io.IOException;
/*    */ import java.io.PrintWriter;
/*    */ import java.sql.ResultSet;
/*    */ import java.sql.SQLException;
/*    */ import java.text.DecimalFormat;
/*    */ import java.util.logging.Level;
/*    */ import java.util.logging.Logger;
/*    */ import javax.servlet.ServletContext;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ 
/*    */ public class NewMapRequest extends ProcessRequest
/*    */ {
/*    */   private final String databaseHost;
/*    */   private final String databaseName;
/*    */   private final String databasePassword;
/*    */   private final String databaseUser;
/*    */ 
/*    */   public NewMapRequest(ServletContext context)
/*    */   {
/* 24 */     this.databaseHost = context.getInitParameter("DatabaseHost");
/* 25 */     this.databaseName = context.getInitParameter("DatabaseName");
/* 26 */     this.databasePassword = context.getInitParameter("DatabasePassword");
/* 27 */     this.databaseUser = context.getInitParameter("DatabaseUser");
/*    */   }
/*    */ 
/*    */   protected void process(HttpServletResponse response, String[] arguments)
/*    */   {
/* 33 */     response.setContentType("text/html; charset=\"UTF-8\"");
/*    */ 
/* 35 */     PrintWriter printWriter = null;
/* 36 */     ConnectionDB connectionDB = null;
/* 37 */     DecimalFormat df = new DecimalFormat("#.#");
/*    */     try
/*    */     {
/* 41 */       printWriter = response.getWriter();
/*    */ 
/* 43 */       connectionDB = new DatabaseMysql(this.databaseHost, this.databaseUser, this.databasePassword, this.databaseName).getConnection();
/*    */ 
/* 45 */       String query = "SELECT substring(zipcode from 1 for 5), location, sum(offeredSpace) FROM User, Identifier WHERE User.email = Identifier.email AND Identifier.lastUpdate > (SELECT DATE_SUB(curdate(), INTERVAL 1 MONTH)) GROUP BY substring(zipcode from 1 for 5), location;";
/*    */ 
/* 50 */       ResultSet resultSet = connectionDB.executeSelect(query);
/*    */ 
/* 52 */       String language = arguments[0];
/*    */ 
/* 54 */       printWriter.println("<HTML>");
/* 55 */       printWriter.println("<HEAD>");
/* 56 */       printWriter.println("<META http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">");
/* 57 */       printWriter.println("<META http-equiv=\"content-language\" content=\"" + language + "\">");
/*    */ 
/* 59 */       if (language.equals("en")) {
/* 60 */         printWriter.println("<META name=\"description\" content=\"Geographical location of rARC backup files.\">");
/* 61 */         printWriter.println("<META name=\"keywords\" content=\"rARC, map, location\">");
/* 62 */         printWriter.println("<TITLE>Geographical location of rARC backup files</TITLE>");
/*    */       }
/*    */       else {
/* 65 */         printWriter.println("<META name=\"description\" content=\"Localização das cópias de segurança do rARC.\">");
/* 66 */         printWriter.println("<META NAME=\"keywords\" CONTENT=\"rARC, mapa, localização\">");
/* 67 */         printWriter.println("<TITLE>Localização geográfica das cópias de segurança do rARC</TITLE>");
/*    */       }
/*    */ 
/* 70 */       printWriter.println("<script src=\"http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAAmD3DSUAtswZGH9DCrDmWihSwyxmI7CPdKdH4sslZO-cSK8Ju6hTrrmcWX7Z6mvNsWGtboDJpbVvn9A&hl=" + language + "\"");
/* 71 */       printWriter.println("type=\"text/javascript\"></script>");
/* 72 */       printWriter.println("<script type=\"text/javascript\">");
/* 73 */       printWriter.println("var geocoder;");
/* 74 */       printWriter.println("var map;");
/* 75 */       printWriter.println("function setMarker(address, space) {");
/* 76 */       printWriter.println("geocoder.getLatLng(address, function(point) {");
/* 77 */       printWriter.println("if (!point) {}");
/* 78 */       printWriter.println("else {");
/* 79 */       printWriter.println("var marker = new GMarker(point);");
/* 80 */       printWriter.println("GEvent.addListener(marker,\"click\", function() {");
/* 81 */       if (language.equals("en"))
/* 82 */         printWriter.println("marker.openInfoWindowHtml(\"<b>Offered space</b>: \"+space+\" GB\");");
/*    */       else
/* 84 */         printWriter.println("marker.openInfoWindowHtml(\"<b>Espaço oferecido</b>: \"+space+\" GB\");");
/* 85 */       printWriter.println("});");
/* 86 */       printWriter.println("map.addOverlay(marker);");
/* 87 */       printWriter.println("}");
/* 88 */       printWriter.println("} ");
/* 89 */       printWriter.println(");");
/* 90 */       printWriter.println("} ");
/* 91 */       printWriter.println("function initialize() {");
/* 92 */       printWriter.println("if (GBrowserIsCompatible()) {");
/* 93 */       printWriter.println("map = new GMap2(document.getElementById(\"map_canvas\"));");
/* 94 */       printWriter.println("map.setUIToDefault();");
/* 95 */       printWriter.println("map.setCenter(new GLatLng(39.5, -8), 7);");
/* 96 */       printWriter.println("geocoder = new GClientGeocoder();");
/*    */ 
/* 100 */       while (resultSet.next())
/*    */       {
/* 102 */         String zipcode = resultSet.getString(1);
/* 103 */         zipcode = zipcode.trim();
/*    */ 
/* 105 */         if ((zipcode != null) && (!zipcode.isEmpty())) {
/* 106 */           zipcode = zipcode.split(" ")[0];
/*    */         }
/* 108 */         printWriter.println("setMarker(\"" + resultSet.getString(2) + " " + zipcode + "\",\"" + df.format(resultSet.getDouble(3) / 1073741824.0D) + "\");");
/*    */       }
/*    */ 
/* 112 */       printWriter.println("}");
/* 113 */       printWriter.println("}");
/* 114 */       printWriter.println("</script>");
/*    */ 
/* 117 */       printWriter.println(" <style type=\"text/css\">");
/* 118 */       printWriter.println("div.c2 {width: 1200px; height: 700px}");
/* 119 */       printWriter.println("div.c1 {text-align: center}");
/* 120 */       printWriter.println("</style>");
/*    */ 
/* 122 */       printWriter.println("</HEAD>");
/* 123 */       printWriter.println("<body onload=\"initialize()\" onunload=\"GUnload()\">");
/* 124 */       printWriter.println("<a href=\"http://www.arquivo.pt\"><img src=\"http://arquivo-web.fccn.pt/logo.jpg\" alt=\"Logotipo AWP\" border=\"0\" ></a><p>");
/*    */ 
/* 126 */       printWriter.println("<div class=\"c1\">");
/*    */ 
/* 128 */       if (language.equals("en")) {
/* 129 */         printWriter.println("<H1>Map with the geographical location of the backup files</H1>");
/* 130 */         printWriter.println("</div>");
/*    */ 
/* 132 */         printWriter.println("<strong>Beta version</strong>");
/*    */       }
/*    */       else {
/* 135 */         printWriter.println("<CENTER><H1>Mapa com a distribuição geográfica das cópias de segurança</H1></CENTER>");
/* 136 */         printWriter.println("</div>");
/*    */ 
/* 138 */         printWriter.println("<strong>Versão experimental</strong>");
/*    */       }
/*    */ 
/* 141 */       printWriter.println("<HR SIZE=1>");
/*    */ 
/* 143 */       printWriter.println("<div id=\"map_canvas\" class=\"c2\"></div>");
/* 144 */       printWriter.println("</BODY>");
/* 145 */       printWriter.println("</HTML>");
/*    */ 
/* 147 */       printWriter.flush();
/* 148 */       printWriter.close();
/*    */ 
/* 150 */       connectionDB.closeStatement();
/* 151 */       connectionDB.close();
/*    */     }
/*    */     catch (SQLException ex) {
/* 154 */       Logger.getLogger(NewMapRequest.class.getName()).log(Level.SEVERE, null, ex);
/*    */     } catch (IOException ex) {
/* 156 */       Logger.getLogger(NewMapRequest.class.getName()).log(Level.WARNING, null, ex);
/*    */     } finally {
/* 158 */       if (printWriter != null) {
/* 159 */         printWriter.close();
/*    */       }
/*    */ 
/* 162 */       if (connectionDB != null)
/*    */         try {
/* 164 */           connectionDB.close();
/*    */         }
/*    */         catch (SQLException ex)
/*    */         {
/*    */         }
/*    */     }
/*    */   }
/*    */ }

/* Location:           C:\Users\Nuno Cruz\Desktop\
 * Qualified Name:     site.NewMapRequest
 * JD-Core Version:    0.6.0
 */